﻿using System;
namespace Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="paringliht_v5_vastus", Namespace="http://producers.arireg.xtee.riik.ee/producer/arireg", Target=typeof(ParinglihtV5Vastus))]
    public class ParinglihtV5VastusSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected IParinglihtV5Vastus clazz;
        
        public ParinglihtV5VastusSerializer(IParinglihtV5Vastus clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            Writer.WriteStartElement("ettevotjad");
            if (clazz.Ettevotjad!=null) {
                global::Xtee.Core.SerializationMetadata metaEttevotjad = this.GetMetaData(clazz.Ettevotjad);
                Writer.WriteTypeAttribute(metaEttevotjad.TypeQualifiedName.Namespace, metaEttevotjad.TypeQualifiedName.Name);
                metaEttevotjad.NewSerializer(clazz.Ettevotjad).WriteXml(Writer);
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Ettevotjad");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("leitud_ettevotjate_arv");
            Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "integer");
            Writer.WriteString(new global::Xtee.Core.Schema.XsdInteger(((decimal)(clazz.LeitudEttevotjateArv))).ToString());
            Writer.WriteEndElement();
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
            if (Reader.LocalName=="ettevotjad") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>paringliht_v5_vastus>ettevotjad");
                }
                global::Xtee.Core.SerializationMetadata metaEttevotjad = this.GetMetaData<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IParinglihtV5Ettevotted>(Reader, "paringliht_v5_ettevotted", "http://producers.arireg.xtee.riik.ee/producer/arireg");
                clazz.Ettevotjad = metaEttevotjad.NewEntity<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IParinglihtV5Ettevotted>();
                if ((Reader.IsEmptyElement == false)) {
                    Reader.ReadStartElement("ettevotjad");
                    metaEttevotjad.NewSerializer(clazz.Ettevotjad).ReadXml(Reader);
                    Reader.ReadEndElement();
                }
                else {
                    Reader.Skip();
                }
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>paringliht_v5_vastus>ettevotjad", Reader.LocalName);
            }
            if (Reader.LocalName=="leitud_ettevotjate_arv") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>paringliht_v5_vastus>leitud_ettevotjate_arv");
                }
                clazz.LeitudEttevotjateArv = new global::Xtee.Core.Schema.XsdInteger(Reader.ReadElementString("leitud_ettevotjate_arv")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>paringliht_v5_vastus>leitud_ettevotjate_arv", Reader.LocalName);
            }
        }
    }
}
